@extends('common.company_template')

@section('content')
    <div class="boxWidth">
        <h3>编辑商品分类</h3>
        @include('common.notice_msg')
        <form method="post" action="{{url('shop/goods/save')}}">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        @if(isset($Goods))
        <input type="hidden" name="Goods[id]" value="{{$Goods->id}}">
        @endif
        <input type="hidden" name="Goods[parent_id]" value="{{$parent_id}}">
        <div class="row editFormItem">
            <div class="col-xs-3"><span>商品名称</span></div>
            <div class="col-xs-8" id="nameBox"><input type="text" class="form-control" id="name" name="Goods[name]" value="{{isset($Goods)?$Goods->name:''}}"><div class="addInputNotice">请输入分类名称</div></div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-3"><span>商品分类</span></div>
            <div class="col-xs-8">
                <select name="Goods[cat]" id="cat">
                    @foreach($Cats as $cat)
                    <option value="{{$cat->id}}">{{$cat->name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        @if(isset($Goods))
        <div class="row editFormItem">
            <div class="col-xs-3"><span>商品时间</span></div>
            <div class="col-xs-8"><input type="text" class="form-control" name="Goods[created_at]" value="{{isset($Goods)?$Goods->created_at:''}}"></div>
        </div>
        @endif
        <div class="row editFormItem">
            <div class="col-xs-3"><span>商品价格</span></div>
            <div class="col-xs-8"><input type="text"class="form-control" name="Goods[price]" value="{{isset($Goods)?$Goods->price:''}}"></div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-3"><span>商品规格</span></div>
            <div class="col-xs-8"><input type="text" id="order" placeholder="请输入规格值空格间隔，例如'冷 热 常温'" class="form-control" name="Goods[kind]" value="{{isset($Goods)?$Goods->kind:''}}"></div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-3"><span>商品说明</span></div>
            <div class="col-xs-8"><input type="text" id="order" placeholder="选填" class="form-control" name="Goods[more]" value="{{isset($Goods)?$Goods->price:''}}"></div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-3"><span>商品状态</span></div>
            <div class="col-xs-8">
                <select name="Goods[status]" id="status">
                    <option value="0">待审</option>
                    <option value="1">通过</option>
                </select>
            </div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-3"><button class="btn btn-primary addInputBtn" type="submit" id="formSubmit">{{isset($Goods)?'更新':'添加'}}</button></div>
            <div class="col-xs-8"></div>
        </div>
        </form>
    </div>
@stop
@section('js')
    <script>
        (function () {
            function hasError(id){
                var str =  $('#'+id).val().replace(/(^\s*)|(\s*$)/g, "");
                if(!str){
                    $('#'+id+'Box').addClass('has-error');
                    return 1;
                }
                return 0;
            }
            $('#formSubmit').on('click',function (e) {
                var sub = 0;
                if(hasError('name')){
                    sub = 1
                }
                if(sub){
                    e.preventDefault();
                }
            });
            @if(isset($Goods))
            $("#status").val({{$Goods->status}});
            $("#cat").val({{$Goods->cat}});
            @endif

        })();
    </script>
@stop